﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

using permit.App_Code.DataAccess;
using permit.App_Code.Entity;

namespace permit.print
{
    public partial class Print : System.Web.UI.Page
    {
        string sturt;
        PrinterAccess prtAcc = new PrinterAccess();
        PermitAccess perAcc = new PermitAccess();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                DataSet ds = prtAcc.GetPrinter(Request.QueryString["priName"]);
                PermitTable permit = perAcc.GetPermit(Convert.ToInt32(Request.QueryString["per_ID"]));

                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    foreach (Control ctl in form1.Controls)
                    {
                        if (ctl is Label)
                        {
                            if (ctl.ID == dr["lable_ID"].ToString())
                            {
                                ((Label)ctl).Font.Name = dr["lable_Font"].ToString();
                                ((Label)ctl).Font.Size = Convert.ToInt32(dr["lable_FontSize"]);
                                ((Label)ctl).Style["top"] = dr["lable_Top"].ToString() + "mm";
                                ((Label)ctl).Style["left"] = dr["lable_Left"].ToString() + "mm";
                                ((Label)ctl).Style["width"] = dr["lable_width"].ToString() + "mm";
                                ((Label)ctl).Style["position"] = "absolute";
                            }
                            switch (ctl.ID)
                            {
                                case "lblDep":
                                    lblDep.Text = permit.Per_Department;
                                    break;
                                case "lblRep":
                                    lblRep.Text = permit.Per_Representative;
                                    break;
                                case "lblAddress":
                                    lblAddress.Text = permit.Per_Address;
                                    break;
                                case "lblType":
                                    lblType.Text = permit.Per_Type;
                                    break;
                                case "lblMark":
                                    lblMark.Text = permit.Per_Mark;
                                    break;
                                case "lblPerCode":
                                    lblPerCode.Text = permit.Per_PermitCode;
                                    break;
                                case "lblOrgan":
                                    lblOrgan.Text = permit.Per_Organ;
                                    break;
                                case "lblDateY":
                                    lblDateY.Text = permit.PermitDate.Year.ToString();
                                    break;
                                case "lblDateM":
                                    lblDateM.Text = permit.PermitDate.Month.ToString();
                                    break;
                                case "lblDateD":
                                    lblDateD.Text = permit.PermitDate.Day.ToString();
                                    break;
                                case "lblStarY":
                                    lblStarY.Text = permit.Per_StarDate.Year.ToString();
                                    break;
                                case "lblStarM":
                                    lblStarM.Text = permit.Per_StarDate.Month.ToString();
                                    break;
                                case "lblStarD":
                                    lblStarD.Text = permit.Per_StarDate.Day.ToString();
                                    break;
                                case "lblEndY":
                                    lblEndY.Text = permit.Per_EndDate.Year.ToString();
                                    break;
                                case "lblEndM":
                                    lblEndM.Text = permit.Per_EndDate.Month.ToString();
                                    break;
                                case "lblEndD":
                                    lblEndD.Text = permit.Per_EndDate.Day.ToString();
                                    break;
                            }
                            if (ctl.ID == "lblPerType")
                            {
                                if (permit.Per_PerType == "新发")
                                {
                                    permit.Per_PerType = "";
                                }
                                lblPerType.Text = permit.Per_PerType;

                            }
                        }
                    }
                }

                Page.RegisterStartupScript("bb", "<script language=javascript>printReport();</script>");
                Page.RegisterStartupScript("aa", "<script language=javascript>printTure();</script>");
            }
        }

    }
}

